package com.itrus.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.SignatureException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.util.Random;
import sun.security.pkcs.PKCS10;
import sun.security.x509.X500Name;
import sun.security.x509.X500Signer;

public class PfxCertStoreUtils
{
  public KeyPair kp = null;
  public String password = "";

  public String generateCSR(String paramString1, int paramInt, String paramString2)
  {
    if (paramString1 != null);
    while (true)
    {
      try
      {
        if (paramString1.length() <= 0)
        {
          break label269;
          KeyPairGenerator localKeyPairGenerator = KeyPairGenerator.getInstance("RSA");
          localKeyPairGenerator.initialize(i, new SecureRandom());
          this.kp = localKeyPairGenerator.generateKeyPair();
          PublicKey localPublicKey = this.kp.getPublic();
          PrivateKey localPrivateKey = this.kp.getPrivate();
          PKCS10 localPKCS10 = new PKCS10(localPublicKey);
          Signature localSignature = Signature.getInstance(str1);
          localSignature.initSign(localPrivateKey);
          String str2 = "defaultUserName";
          if ((paramString2 != null) && (paramString2.length() > 0))
            str2 = paramString2;
          String str3 = "CN=" + str2 + ",C=CN";
          X500Name localX500Name = new X500Name(str3);
          X500Signer localX500Signer = new X500Signer(localSignature, localX500Name);
          localPKCS10.encodeAndSign(localX500Signer);
          ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
          localPKCS10.print(new PrintStream(localByteArrayOutputStream));
          String str4 = localByteArrayOutputStream.toString().replaceAll("\r|\n", "").replaceAll("-----BEGIN NEW CERTIFICATE REQUEST-----", "").replaceAll("-----END NEW CERTIFICATE REQUEST-----", "");
          return str4;
        }
        else
        {
          str1 = paramString1;
        }
      }
      catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
      {
        localNoSuchAlgorithmException.printStackTrace();
        return null;
      }
      catch (InvalidKeyException localInvalidKeyException)
      {
        localInvalidKeyException.printStackTrace();
        continue;
      }
      catch (IOException localIOException)
      {
        localIOException.printStackTrace();
        continue;
      }
      catch (CertificateException localCertificateException)
      {
        localCertificateException.printStackTrace();
        continue;
      }
      catch (SignatureException localSignatureException)
      {
        localSignatureException.printStackTrace();
        continue;
      }
      label269: String str1 = "SHA1WithRSA";
      int i = 1024;
      if (paramInt != 0)
        i = paramInt;
    }
  }

  public String generatePassword(int paramInt)
  {
    String str = Integer.toString(Math.abs(new Random().nextInt()));
    for (int i = paramInt - str.length(); ; i--)
    {
      if (i <= 0)
        return this.password + str;
      this.password += "0";
    }
  }

  public String generatePkcs12(String paramString1, KeyPair paramKeyPair, String paramString2)
  {
    try
    {
      Certificate[] arrayOfCertificate = { CertUtils.getX509CertificateFromBase64(paramString2.replaceAll("\r\n", "").replaceAll("\r", "").replaceAll("\n", "")) };
      System.out.println("usered password:" + paramString1);
      KeyStore localKeyStore = KeyStore.getInstance("PKCS12");
      localKeyStore.load(null, paramString1.toCharArray());
      localKeyStore.setKeyEntry("pkcs12", paramKeyPair.getPrivate(), paramString1.toCharArray(), arrayOfCertificate);
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
      localKeyStore.store(localByteArrayOutputStream, paramString1.toCharArray());
      String str = new String(Base64.encode(localByteArrayOutputStream.toByteArray()));
      return str;
    }
    catch (CertificateException localCertificateException)
    {
      localCertificateException.printStackTrace();
      return null;
    }
    catch (KeyStoreException localKeyStoreException)
    {
      while (true)
        localKeyStoreException.printStackTrace();
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      while (true)
        localNoSuchAlgorithmException.printStackTrace();
    }
    catch (IOException localIOException)
    {
      while (true)
        localIOException.printStackTrace();
    }
  }

  public String getBase64KeyPair()
  {
    return new String(Base64.encode(this.kp.toString().getBytes()));
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.util.PfxCertStoreUtils
 * JD-Core Version:    0.6.2
 */